package com.yhy.server.controller;


import com.yhy.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private UserService userService;

    @GetMapping("/findAll")
    public ResponseEntity findAll(String mobile){
        return userService.findByMobile(mobile);
    }

    @PostMapping("/saveUser")
    public ResponseEntity saveUser(@RequestBody Map<String,Object> param){
        String mobile = (String) param.get("mobile");
        String password = (String) param.get("password");
        return userService.saveUser(mobile,password);
    }

    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map param){
        String mobile = (String) param.get("phone");
        return userService.sendSms(mobile);
    }
    /**
     * /loginVerification
     */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map param){
        String mobile = (String) param.get("phone");
        String code = (String) param.get("verificationCode");
        return userService.phoneLogin(mobile,code);
    }
}
